/**
 * 
 */
package com.et114.modules.products.search;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.et114.components.simpletable.DataList;
import com.et114.core.action.BaseDispatchAction;

/*
 * @author guanhw
 */
public class SearchAction extends BaseDispatchAction {
	public  ActionForward search4View( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		SearchForm  sform = ( SearchForm ) form ; 
		sform.setPageSize ( 10 ) ;
		String key = sform.getKeyWord ( ) ; 
		if ( !StringUtils.isEmpty ( key ) && !StringUtils.isBlank ( key ) ) {
			//do compass search 
			SearchService searchCompass = ( SearchService ) getBean( "searchCompass" ) ;
			DataList dl = searchCompass.search ( key , sform.getPageNum ( ) , sform.getPageSize ( ) ) ; 
			request.setAttribute ( "dl" , dl ) ; 
		}
		
		request.setAttribute ( "key" , key ) ;
		return mapping.findForward ( "searchReult"  ) ;
	}

}
